package com.xinruke.hostels.finance.interfaces.api;

import com.xinruke.hostels.common.fallback.FeignFallback;
import com.xinruke.hostels.common.vo.ResultVO;
import com.xinruke.hostels.finance.interfaces.dto.UserBalanceQueryDto;
import com.xinruke.hostels.finance.interfaces.dto.UserBalanceQueryResultDTO;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @ClassName UserFinanceFallback
 * @CreateDate 2019/6/9
 * @Author FengXinQiang
 * @Version V1.0.0.0
 * @Decription 用户资金接口熔断处理
 */
@Component
public class UserFinanceFallback implements FallbackFactory<UserFinanceApi> {
    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private FeignFallback feignFallback;

    @Override
    public UserFinanceApi create(Throwable throwable) {
        logger.error("系统异常", throwable);

        return new UserFinanceApi() {
            @Override
            public ResultVO<UserBalanceQueryResultDTO> balance(UserBalanceQueryDto userBalanceQueryDto) {
                return feignFallback.doFallback(UserFinanceFallback.class, "balance", "查询余额");
            }
        };
    }
}
